package com.ssy.lingxi.purchase.controller.purchaseplan;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.request.*;
import com.ssy.lingxi.purchase.api.dto.response.PurchasePlanListResponse;
import com.ssy.lingxi.purchase.api.dto.response.PurchasePlanResponse;
import com.ssy.lingxi.purchase.entity.purchaseplan.PurchasePlanDetail;
import com.ssy.lingxi.purchase.service.purchaseplan.PurchasePlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @menu 采购能力 - 采购计划管理
 * @author fhj
 * @version 2.0.0
 * @date 2021/02/26
 */
@RestController
@RequestMapping("/purchase/purchase/plan")
public class PurchasePlanController extends BaseController {

    @Resource
    private PurchasePlanService purchasePlanService;

    @ApiOperation(value = "内部状态")
    @GetMapping(value = "/inner")
    public Wrapper<List<Map<String, Object>>> inner() {
        return purchasePlanService.inner();
    }

    @ApiOperation(value = "列表（所有）")
    @GetMapping(value = "/allList")
    public Wrapper<PageData<PurchasePlanListResponse>> allList(@Valid PurchasePlanListRequest qo, HttpServletRequest request) {
        return purchasePlanService.allList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待提交审核）")
    @GetMapping(value = "/toBeSubmitExamList")
    public Wrapper<PageData<PurchasePlanListResponse>> toBeSubmitExamList(@Valid PurchasePlanListRequest qo, HttpServletRequest request) {
        return purchasePlanService.toBeSubmitExamList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待一级审核）")
    @GetMapping(value = "/toBeFirstExamList")
    public Wrapper<PageData<PurchasePlanListResponse>> toBeFirstExamList(@Valid PurchasePlanListRequest qo, HttpServletRequest request) {
        return purchasePlanService.toBeFirstExamList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待二级审核）")
    @GetMapping(value = "/toBeSecondExamList")
    public Wrapper<PageData<PurchasePlanListResponse>> toBeSecondExamList(@Valid PurchasePlanListRequest qo, HttpServletRequest request) {
        return purchasePlanService.toBeSecondExamList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待执行）")
    @GetMapping(value = "/toBeExecuteList")
    public Wrapper<PageData<PurchasePlanListResponse>> toBeExecuteList(@Valid PurchasePlanListRequest qo, HttpServletRequest request) {
        return purchasePlanService.toBeExecuteList(qo, getSysUser(request));
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "/details")
    public Wrapper<PurchasePlanResponse> details(@Valid CommonIdRequest dto, HttpServletRequest request) {
        return purchasePlanService.details(dto, getSysUser(request));
    }

    @ApiOperation(value = "采购计划明细")
    @GetMapping(value = "/purchasePlanDetail")
    public Wrapper<PageData<PurchasePlanDetail>> purchasePlanDetail(@Valid CommonIdPageRequest dto, HttpServletRequest request) {
        return purchasePlanService.purchasePlanDetail(dto, getSysUser(request));
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Valid UpdatePurchasePlanRequest dto, HttpServletRequest request) {
        return purchasePlanService.update(dto, getSysUser(request));
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Valid CommonIdRequest dto, HttpServletRequest request) {
        return purchasePlanService.delete(dto, getSysUser(request));
    }

    @ApiOperation(value = "提交审核")
    @PostMapping(value = "/submitExam")
    public Wrapper<Void> submitExam(@RequestBody @Valid CommonIdRequest dto, HttpServletRequest request) {
        return purchasePlanService.submitExam(dto, getSysUser(request));
    }

    @ApiOperation(value = "审核（一级）")
    @PostMapping(value = "/firstExam")
    public Wrapper<Void> firstExam(@RequestBody @Valid CommonExamRequest dto, HttpServletRequest request) {
        return purchasePlanService.firstExam(dto, getSysUser(request));
    }

    @ApiOperation(value = "审核（二级）")
    @PostMapping(value = "/secondExam")
    public Wrapper<Void> secondExam(@RequestBody @Valid CommonExamRequest dto, HttpServletRequest request) {
        return purchasePlanService.secondExam(dto, getSysUser(request));
    }
}
